package day9.homework;

//写两个线程，一个线程打印 1-52，另一个线程打印A-Z，打印顺序是12A34B…5152Z
public class PrintDemo2 {
    static int count = 0;
    public synchronized void print1(){
        int printNum = 1;
        while (printNum<=52){
            if (count%3!=2){
                for (int i = 0; i < 2; i++) {
                    notifyAll();
                    System.out.print(printNum);
                    count++;
                    printNum++;
                }
            }
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public synchronized void print2(){
        for (int i = 1; i <= 26; i++) {
            if (count%3 == 2){
                notifyAll();
                System.out.print((char)(i+64));
                count++;
            }
            try {
                wait();
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
    public static void main(String[] args) {
        PrintDemo2 pd = new PrintDemo2();
        new Thread(()->pd.print1()).start();
        new Thread(()->pd.print2()).start();
    }
}
